from typing import List, Optional
from pydantic import BaseModel, Field
from datetime import datetime


class EvaluationItem(BaseModel):
    """评估项数据模型"""
    id: str
    module: str
    category: str
    checkpoint: str
    materials: List[str] = Field(default_factory=list)
    notes: str
    selected: Optional[bool] = None
    updated_at: Optional[str] = None  # 保持与前端字符串时间格式兼容


class SnapshotCreate(BaseModel):
    """创建快照请求模型"""
    assessment_type: str
    name: str  # 必填
    evaluation_items: List[EvaluationItem] = Field(default_factory=list)


class SnapshotUpdate(BaseModel):
    """更新快照请求模型"""
    name: Optional[str] = None
    evaluation_items: Optional[List[EvaluationItem]] = None


class SnapshotResponse(BaseModel):
    """单个快照响应模型"""
    id: str
    assessment_type: str
    name: str
    saved_at: datetime
    evaluation_items: List[EvaluationItem] = Field(default_factory=list)
    shared_id: Optional[str] = None  # GET 时可填充，用于初始化会话

    class Config:
        from_attributes = True


class SnapshotListResponse(BaseModel):
    """快照列表响应模型"""
    snapshots: List[SnapshotResponse]
    total: int
